/*
 * graphics.h : public function and datatypes for using OS graphics sub-system.
 *
 * Written by T.Pierron, June 2008
 */

#ifndef	SIT_GRAPHICS_H
#define	SIT_GRAPHICS_H

#include <wchar.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct GC_t *        GC;
typedef struct TextFont_t    TextFont;
#ifndef	SIT_IMAGE_DEF
typedef struct Image_t *     Image;
#endif

#include "SIT.h"

DLLIMP GC   GFX_GetGC(SIT_Widget);
DLLIMP GC   GFX_AllocOffScreen(SIT_Widget, int w, int h);
DLLIMP void GFX_Free(GC);
DLLIMP void GFX_FreeImage(Image);
DLLIMP void GFX_SetDrMd(GC, int mode);
DLLIMP void GFX_Move(GC, int x, int y);
DLLIMP void GFX_Draw(GC, int x, int y);
DLLIMP void GFX_3dRect(GC, int x, int y, int w, int h, int borders, int raised);
DLLIMP void GFX_DrawRect(GC, int x, int y, int x2, int y2);
DLLIMP void GFX_FillRect(GC, int x, int y, int x2, int y2);
DLLIMP void GFX_FillRectS(GC, Rect *);
DLLIMP void GFX_FillElipse(GC, int x, int y, int x2, int y2);
DLLIMP void GFX_XorRect(GC gc, int x, int y, int w, int h);
DLLIMP void GFX_CopyGC(GC src, int xs, int ys, int ws, int hs, GC dst, int xd, int yd);
DLLIMP void GFX_SetTextColor(GC, int color);
DLLIMP void GFX_SwapFgBg(GC);
DLLIMP void GFX_SetBgColor(GC, int color);
DLLIMP void GFX_SetPen(GC, int width, ULONG color);
DLLIMP void GFX_GetRefresh(GC, Rect *);
DLLIMP void GFX_FillPolygon(GC, int * points, int nb, int mode);
DLLIMP void GFX_Polygon(GC, int * points, int nb, int mode);
DLLIMP void GFX_FillGradient(GC, Rect *, int orient, ULONG col1, ULONG col2, ...);
DLLIMP void GFX_GetFontInfo(GC, TextFont * out);
DLLIMP int  GFX_SetSysColor(GC, int color, Bool bg);
DLLIMP int  GFX_Text(GC, STRPTR text, int len, int x, int y);
DLLIMP int  GFX_TextW(GC, const wchar_t * text, int len, int x, int y);
DLLIMP int  GFX_TextLength(GC, STRPTR str, int len);
DLLIMP int  GFX_TextLengthW(GC, const wchar_t * str, int len);
DLLIMP int  GFX_TextFit(GC, STRPTR str, int bytes, int maxwidth, int * width);
DLLIMP void GFX_CloseFont(APTR hfont);
DLLIMP void GFX_SetFont(GC, APTR font);
DLLIMP void GFX_GetPos(GC, int * x, int * y);
DLLIMP void GFX_SetPixel(GC gc, int x, int y);
DLLIMP long GFX_GetColor(GC, Bool bg);
DLLIMP APTR GFX_LoadFont(STRPTR family, int h, int weight, int style);
DLLIMP APTR GFX_GetFont(STRPTR fmt);
DLLIMP void GFX_SetPixels(Image src, int xs, int ys, int ws, int hs,
                          GC dst, int xd, int yd, int wd, int hd);
DLLIMP void GFX_Scroll(SIT_Widget, int dx, int dy, int x, int y, int w, int h);
DLLIMP Bool GFX_SetPatBrush(GC, Image);
DLLIMP APTR GFX_LoadImage(STRPTR img);
DLLIMP APTR GFX_LoadImageFromBuf(APTR data, int length);
DLLIMP APTR GFX_GetSysImage(STRPTR path, STRPTR * desc, STRPTR * type);
DLLIMP APTR GFX_CreateImage(int w, int h, int bpp);
DLLIMP APTR GFX_CreateImageEx(int w, int h, int bpp, int extra);
DLLIMP APTR GFX_GetFont(STRPTR fmt);
DLLIMP APTR GFX_GetDevice(GC);
DLLIMP void GFX_ExcludeClipRect(GC, int x, int y, int w, int h);
DLLIMP void GFX_SetBgFill(GC, APTR bitmap);
DLLIMP void GFX_FlattenImage(Image, ULONG color);
DLLIMP void GFX_ToNativeFormat(Image);
DLLIMP int  GFX_GetStage(GC);
DLLIMP Bool GFX_ScreenCap(Image dest, int x, int y);

#define GFX_FillElipseS(gc, struct_rect) \
	GFX_FillElipse(gc, struct_rect.x, struct_rect.y, struct_rect.x + struct_rect.width - 1, struct_rect.y + struct_rect.height - 1)

enum /* Possible valuse for 'format' in GFX_SetPixels */
{
	GFX_FormatK,
	GFX_FormatRGB,
	GFX_FormatBGR,
	GFX_FormatRGBA,
	GFX_FormatABGR
};

enum /* Possible values for 'mode' in GFX_FillPolygon */
{
	GFX_CoordModeAbs      = 0x00,
	GFX_CoordModePrevious = 0x01,
	GFX_BezierCurve       = 0x02,   // GFX_Polygon only (flag)
	GFX_ClosePolygon      = 0x04    // GFX_Polygon only (flag)
};

enum /* Possible values for 'style' in GFX_LoadFont */
{
	GFX_FSItalic    = 0x01,
	GFX_FSUnderline = 0x02,
	GFX_FSStrike    = 0x04
};

#define	GFX_ColorStop   0xffffffffUL

#define	SYSCOL(col)     ((1UL << 31) | col)
#define	ISSYS(col)      (col & (1UL << 31))

enum /* System colors */
{
	GFX_ColorText,
	GFX_ColorDarkShadow,
	GFX_Color3dFace,
	GFX_Color3dHighlight,
	GFX_Color3dLight,
	GFX_Color3dShadow,
	GFX_ColorBgDesktop,
	GFX_ColorBgDialog,
	GFX_ColorFgControl,
	GFX_ColorFgCaption,
	GFX_ColorGrayedText,
	GFX_ColorBgHighlight,
	GFX_ColorFgHighlight,
	GFX_ColorHotLink,
	GFX_ColorBgToolTip,
	GFX_ColorFgToolTip,
	GFX_ColorBgMenu,
	GFX_ColorFgMenu,
	GFX_ColorBgSelMenu,
	GFX_ColorFgSelMenu,
	GFX_ColorBgWindow,
	GFX_ColorTransparent,
	GFX_ColorNum
};

enum /* values for 'mode' of GFX_SetDrMd */
{
	GFX_MODEJAM1,    /* Bg is transparent (Text, dashed lines) */
	GFX_MODEJAM2     /* Bg is filled with bg color */
};

/* Alias */
#define	GFX_TxtModeTransparent     GFX_MODEJAM1
#define	GFX_TxtModeOpaque          GFX_MODEJAM2

struct TextFont_t
{
	int  height;
	int  ascent;
	int  descent;
	int  avgwidth;
	int  maxwidth;
	Bool fixed;
	TEXT name[40];
};

struct Image_t
{
	int   width;
	int   height;
	int   format;
	int   stride;
	int   encoder;
	int   bpp;
	DATA8 bitmap;
	DATA8 palette;
	APTR  hbitmap;
};

#ifndef SETU32
#define SETU32(dst, src)    * (uint32_t *) (dst) = * (uint32_t *) (src)
#endif

/* For custom cursor bitmap */
#define SETHOTSPOT(img, x, y)   ((img)->encoder = (x) | ((y) << 8))

enum /* Possible values for Image->encoder */
{
	GFX_EncoderUnknown = 0,
	GFX_EncoderBMP     = 1,
	GFX_EncoderJPEG    = 2,
	GFX_EncoderPNG     = 3,
	GFX_Premultiplied  = 0x8000,
	GFX_GlobalAlloced  = 0x10000 /* For clipboard */
};

#ifdef __cplusplus
}
#endif
#endif
